package processcontrol

import "fmt"

func Execute() {
	TestDeferOrder()
}

func TestDeferOrder() {
	defer println("AAAAA")
	defer println("BBBBB")
	defer println("CCCCC")
}

func TestDeferFunc() {

	str := "AAAA"

	defer func(s string) {
		fmt.Printf("s: %v\n", s)
	}(str)

	str = "BBBBB"
	fmt.Printf("str: %v\n", str)
}

func TestDefer() {
	str := "BBBBB"
	defer fmt.Println(str)
	str = "AAAAA"
	fmt.Println(str)
}

func TestGotoNormal() {
	i := 1
loopPrint:
	if i <= 5 {
		fmt.Printf("i: %v\n", i)
		i++
		goto loopPrint
	}

	j := 1
	for {
		if j >= 5 {
			goto loopBreak
		}
		fmt.Printf("j: %v\n", j)
		j++
	}
loopBreak:

	k := 1
loopContinue:
	for k <= 5 {
		if k%2 == 1 {
			k++
			goto loopContinue
		}
		fmt.Printf("k: %v\n", k)
		k++
	}
}

func TestGoto() {
	goto printB
	fmt.Println("AAAAA")
printB:
	fmt.Println("BBBBB")
}

func TestFor() {
	a := 1
	for a <= 5 {
		fmt.Printf("a: %v\n", a)
		a++
	}

	for i := 1; i <= 5; i++ {
		fmt.Printf("i: %v\n", i)
	}

	rangeArr := []string{"C1", "C2", "C3"}
	for _, item := range rangeArr {
		fmt.Printf("item: %v\n", item)
	}

	number := 0
	for {
		if number >= 5 {
			break
		}
		fmt.Printf("number: %v\n", number)
		number++
	}

}

func TestSwitchFallThrough() {
	condition := "CASE1"

	switch condition {
	case "CASE1", "CASE3", "CASE5":
		fmt.Println("ODD PRINT")
		fallthrough
	case "CASE2", "CASE4", "CASE6":
		fmt.Println("EVEN PRINT")
	default:
		fmt.Println("DEFAULT PRINT")
	}
}

func TestSwitchCaseFunc() {
	switch GetCondition("ONE") {
	case 1:
		fmt.Print("ONE PRINT")
	case 0:
		fmt.Print("TWO PRINT")
	default:
		fmt.Print("DEFAULT")
	}
}

func TestSwitchCaseThreeCase() {
	condition := "CASE2"

	switch condition {
	case "CASE1", "CASE3", "CASE5":
		fmt.Println("ODD PRINT")
	case "CASE2", "CASE4", "CASE6":
		fmt.Println("EVEN PRINT")
	default:
		fmt.Println("DEFAULT PRINT")
	}
}

func TestIfElse(condition string) {

	if condition == "1" {
		fmt.Println("ONE")
	} else if condition == "2" {
		fmt.Println("TWO")
	} else if condition == "3" {
		fmt.Println("THREE")
	} else {
		fmt.Println("OTHER")
	}
}

func TestIfElseHight() {
	if a := GetCondition("ONE"); a == 1 {
		fmt.Println("TEST")
	}
}

func GetCondition(condition string) int {
	if condition == "ONE" {
		return 1
	}
	return 0
}
